Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove tracing::info usage #578

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Conversation

dutterbutter
Copy link
Collaborator

@dutterbutter dutterbutter commented Feb 4, 2025

What πŸ’»

  • Turns off tracing::info! in favour of shell wrapper and macro usage. A simplified version of Foundry's shell wrapper.
  • Removes the timestamp for warn, error, debug, trace logs

Why βœ‹

Evidence πŸ“·

Include screenshots, screen recordings, or console output here demonstrating that your changes work as intended

@dutterbutter dutterbutter marked this pull request as ready for review February 4, 2025 02:05
@dutterbutter dutterbutter requested a review from a team as a code owner February 4, 2025 02:05
@dutterbutter dutterbutter marked this pull request as draft February 4, 2025 13:48
Cargo.toml Outdated Show resolved Hide resolved
spec-tests/src/patch.rs Outdated Show resolved Hide resolved
crates/common/src/shell.rs Outdated Show resolved Hide resolved
@dutterbutter dutterbutter marked this pull request as ready for review February 6, 2025 16:39
@dutterbutter
Copy link
Collaborator Author

dutterbutter commented Feb 6, 2025

@itegulov based on the proposal feedback, I turned off tracing::info by default, and adjusted some existing log levels. I did so quite arbitrarily so please feel free to suggest changing the level or removing completely. We are still logging out tx summary / console logs by default but intend to update in #577.

For revert / halts and logs in formatter.rs those will be subsequently updated in #571 and #577.

@dutterbutter dutterbutter added the needs review πŸ‘“ PR requires a review label Feb 7, 2025
Copy link
Member

@popzxc popzxc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM


[dependencies]
anstream.workspace = true
anstyle.workspace = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing newline

Comment on lines 114 to 119
let prefix = if self.should_color() {
format!("{}Warning:{} ", WARN, Reset)
} else {
"Warning: ".to_string()
};
self.println_err(&format!("{}{}", prefix, msg))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (here and in other places): extra allocations seem unjustified, we could easily just write to stdout/stderr.
Not that it's a performance concern, just feels not very clean. In that regard, I like foundry approach more.

@@ -55,7 +56,7 @@ impl InMemoryNode {
message
);

tracing::info!("{}", pretty_message.on_red());
sh_eprintln!("\n{}", pretty_message.on_red());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other places: why do we need \n to be inserted manually?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for readability, more opinionated than anything. For example, since we are still printing tx summary currently, without \n in some places you get:

βœ…  [SUCCESS] Hash: 0x9c159398838efc27c9b8e0f858d39914c2d57a28e264a21124898f7ce0f99973
Initiator: 0xbd29a1b981925b94eec5c4f1125af02a2ec4d1ca
Payer: 0xbd29a1b981925b94eec5c4f1125af02a2ec4d1ca
Gas Limit: 317_069 | Used: 317_069 | Refunded: 0
Paid: 0.0000143474 ETH (317069 gas * 0.04525000 gwei)
Refunded: 0.0000000000 ETH
execution reverted: Ownable: caller is not the owner
Traces:
  [18748] RichAccount::validateTransaction(0x3a01cb7f742913bc3ad049e8d38aa733b6b5109900bfc32050b34553fcec9f54, 0xa4da2b8671d03015e54f04c404bcc833ad27ce876378f46c5de0f7fe0cede56a, (113, 310456771025820669616026695872740475403597889609 [3.104e47], 32774 [3.277e4], 1073938 [1.073e6], 50000 [5e4], 45250000 [4.525e7], 45250000 [4.525e7], 0, 4, 0, [0, 0, 0, 0], 0x9c4d535b0000000000000000000000000000000000000000000000000000000000000000010001556e69cb167b6cd0feb302b363b7045e5a8d960f60593983b2690bad39000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000, 0x633c8fc52cea7cb7d52edf9987fc2e090a39071e5f61cf81cadbf56653557d4f14fa7d4307f2164b37e852a04400db1165490f7d2febf7c6461fad44d186750f1c, [0x010001556e69cb167b6cd0feb302b363b7045e5a8d960f60593983b2690bad39], 0x, 0x))
    └─ ← [Success] 202bcce700000000000000000000000000000000000000000000000000000000
  [8691] RichAccount::payForTransaction(0x3a01cb7f742913bc3ad049e8d38aa733b6b5109900bfc32050b34553fcec9f54, 0xa4da2b8671d03015e54f04c404bcc833ad27ce876378f46c5de0f7fe0cede56a, (113, 310456771025820669616026695872740475403597889609 [3.104e47], 32774 [3.277e4], 1073938 [1.073e6], 50000 [5e4], 45250000 [4.525e7], 45250000 [4.525e7], 0, 4, 0, [0, 0, 0, 0], 0x9c4d535b0000000000000000000000000000000000000000000000000000000000000000010001556e69cb167b6cd0feb302b363b7045e5a8d960f60593983b2690bad39000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000, 0x633c8fc52cea7cb7d52edf9987fc2e090a39071e5f61cf81cadbf56653557d4f14fa7d4307f2164b37e852a04400db1165490f7d2febf7c6461fad44d186750f1c, [0x010001556e69cb167b6cd0feb302b363b7045e5a8d960f60593983b2690bad39], 0x, 0x))
    └─ ← [Success]
  [43918] RichAccount::executeTransaction(0x3a01cb7f742913bc3ad049e8d38aa733b6b5109900bfc32050b34553fcec9f54, 0xa4da2b8671d03015e54f04c404bcc833ad27ce876378f46c5de0f7fe0cede56a, (113, 310456771025820669616026695872740475403597889609 [3.104e47], 32774 [3.277e4], 1073938 [1.073e6], 50000 [5e4], 45250000 [4.525e7], 45250000 [4.525e7], 0, 4, 0, [0, 0, 0, 0], 0x9c4d535b0000000000000000000000000000000000000000000000000000000000000000010001556e69cb167b6cd0feb302b363b7045e5a8d960f60593983b2690bad39000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000, 0x633c8fc52cea7cb7d52edf9987fc2e090a39071e5f61cf81cadbf56653557d4f14fa7d4307f2164b37e852a04400db1165490f7d2febf7c6461fad44d186750f1c, [0x010001556e69cb167b6cd0feb302b363b7045e5a8d960f60593983b2690bad39], 0x, 0x))
    β”œβ”€ [12412] β†’ new <unknown>@0x4b5df730c2e6b28e17013a1485e5d9bc41efe021
    β”‚   β”œβ”€ emit OwnershipTransferred(param0: 0x0000000000000000000000000000000000000000, param1: RichAccount: [0x36615Cf349d7F6344891B1e7CA7C72883F5dc049])
    β”‚   └─ ← [Success] 64 bytes of code
    └─ ← [Success] 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000

Copy link
Contributor

@itegulov itegulov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good conceptually, some logs were misconverted though IMHO

sh_println!("Genesis Timestamp");
sh_println!("========================");
sh_println!("{}", self.get_genesis_timestamp().to_string().green());
sh_println!("\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I have wanted to do for a while is to refactor this file to print using raw strings instead, like this:

sh_print!(
    r#"

Genesis Timestamp
========================
{}

    "#,
    self.get_genesis_timestamp().to_string().green()
);

The code indents won't be pretty but it will be easy to see what each table looks like (and ensure that fields are properly aligned etc). Can be done in a separate PR ofc

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh this is much better πŸ‘

Comment on lines 845 to 860
sh_println!("\n{} [{}] Hash: {:?}", emoji, status, tx.hash());
sh_println!("Initiator: {:?}", tx.initiator_account());
sh_println!("Payer: {:?}", tx.payer());
sh_println!(
"Gas Limit: {} | Used: {} | Refunded: {}",
to_human_size(tx.gas_limit()),
to_human_size(used_gas),
to_human_size(tx_result.refunds.gas_refunded.into())
);
tracing::info!(
sh_println!(
"Paid: {:.10} ETH ({} gas * {})",
paid_in_eth,
used_gas,
format_gwei(l2_gas_price.into())
);
tracing::info!("Refunded: {:.10} ETH", refunded_in_eth);
sh_println!("Refunded: {:.10} ETH", refunded_in_eth);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here potentially. Note: you can use variable in interpolation directly and named parameters like this: sh_println!("{argument}", argument = "test"). See fmt

tracing::debug!(
"set code: address={:?}, bytecode_hash={:?}",
address,
BytecodeHash::for_bytecode(&bytecode).value()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order was correct before, this is how you output structured logs/events in tracing. See docs

latest_number,
latest_hash,
latest_batch_number,
latest_timestamp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Err(Web3Error::SubmitTransactionError(pretty_message, data))
}
ExecutionResult::Halt { reason } => {
tracing::info!("{}", format!("Unable to estimate gas for the request with our suggested gas limit of {}. The transaction is most likely unexecutable. Breakdown of estimation:", suggested_gas_limit + overhead).red());
tracing::info!(
tracing::debug!("{}", format!("Unable to estimate gas for the request with our suggested gas limit of {}. The transaction is most likely unexecutable. Breakdown of estimation:", suggested_gas_limit + overhead).red());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other places: no need to colorize tracing logs, then format! arguments can be inlined

@@ -111,7 +112,7 @@ impl NodeExecutor {
// Reply to sender if we can, otherwise hold result for further processing
let result = if let Some(reply) = reply {
if let Err(result) = reply.send(result) {
tracing::info!("failed to reply as receiver has been dropped");
sh_eprintln!("failed to reply as receiver has been dropped");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave reply failures as tracing logs. If receiver was dropped then it (likely) means network connection with users client (ethers, hardhat script etc) got severed for some reason. Not super actionable from user's side.

"Failed to send transaction notification because channel is full",
sh_warn!(
"Failed to send transaction notification because channel is full: {}",
tx_hash,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -139,7 +139,6 @@ impl InMemoryNode {
if let Some(bytecode) = self.storage.load_factory_dep_alt(hash).await? {
return Ok(Some(bytecode));
}
println!("Nope");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, this println sneaking through reminded me of below. IYKYK
balatro-card

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review πŸ‘“ PR requires a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor: Replace tracing::info! with stdout
3 participants